package com.jiuyuejiu.func_book;

import android.content.Intent;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import com.jiuyuejiu.R;
import com.jiuyuejiu.base.BaseActivity;
import com.jiuyuejiu.websetting.JsBridge;
import com.jiuyuejiu.websetting.JsInterface;
import com.kylin.core.loader.LatteLoader;
import com.kylin.core.web.WebDelegateImpl;

import java.lang.ref.SoftReference;


/**
 * web Activity
 */
public class WebActivity extends BaseActivity {


    MyHandler handler;


    private String weburl;


    /**
     * 接收子线程消息的 Handler
     */
    public static class MyHandler extends Handler {

        // 软引用
        SoftReference<WebActivity> fragmentRef;

        public MyHandler(WebActivity fragment) {
            fragmentRef = new SoftReference<WebActivity>(fragment);
        }

        @Override
        public void handleMessage(Message msg) {
            WebActivity fragment = fragmentRef.get();
            if (fragment == null) {
                return;
            }
            Bundle bundle = msg.getData();

            // 处理UI 变化
            switch (msg.what) {
                case 0:
                    // fragment.finishSuc();
                    break;
                case 1:
                    // fragment.showShareWx(bundle);
                    break;
                case 2:
                    // fragment.showTzAdapter();
                    break;
            }
        }
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        LatteLoader.showLoading(WebActivity.this);

        // 全屏
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_msg_web);


        handler = new MyHandler(this);
        // 获取上一页传递过来的数据
        Intent i = getIntent();
        weburl = i.getStringExtra("weburl");

        WebDelegateImpl delegate = WebDelegateImpl.create(weburl);

        loadRootFragment(R.id.fl_container_webview, delegate);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
